//判断网络当前网络情况
import 'package:connectivity/connectivity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_app/blocs/network_connectivity_bloc/network_connectivity_bloc.dart';
class NetworkConnectivity{
  final NetWorkConnectivityBloc netWorkConnectivityBloc;
  var _subscription;
  NetworkConnectivity({@required this.netWorkConnectivityBloc}){
    _subscription=Connectivity().onConnectivityChanged.listen(
            (ConnectivityResult result) {
          // Got a new connectivity status!
          if (result == ConnectivityResult.mobile) {
            //手机网络
            // I am connected to a mobile network.
            netWorkConnectivityBloc.add(NetWorkConnectivityEvent(isShow: true,connectivityType: ConnectivityType.MobileNetwork));
          }
          else if (result == ConnectivityResult.wifi) {
            //wifi网络
            // I am connected to a wifi network.
          }else{
            //没有网络
          }
        });
  }
  dispose(){
    _subscription.cancel();
  }
}